package com.wf.DouDiZhuOL;

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileInputStream;
import java.util.Date;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import com.google.protobuf.DescriptorProtos;
import com.google.protobuf.Descriptors;
import com.google.protobuf.DynamicMessage;
import com.google.protobuf.Message;

public class MainFrame {

	private JFrame frame;
	private static JTextArea textArea;
	
	private ServerUnit serverUnit;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainFrame window = new MainFrame();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public MainFrame() {
		initialize();
	}
	
	public static void setText(String _content) 
	{
		textArea.append(new Date(System.currentTimeMillis()) + ":   " + _content + "\n");
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		serverUnit = new ServerUnit();
		
		frame = new JFrame();
		frame.setBounds(100, 100, 450, 348);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		JButton startBtn = new JButton("服务器启动");
		startBtn.setBounds(60, 10, 100, 31);
		startBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				serverUnit.startServer();
			}
		});
		frame.getContentPane().add(startBtn);
		
		JButton stopBtn = new JButton("服务器停止");
		stopBtn.setBounds(270, 10, 100, 31);
		stopBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				serverUnit.stopServer();
			}
		});
		frame.getContentPane().add(stopBtn);
		
		textArea = new JTextArea();
		textArea.setBounds(10, 62, 414, 238);
		textArea.setCaretPosition(textArea.getText().length());   
		
		JScrollPane scrollPane = new JScrollPane(textArea);
		scrollPane.setBounds(10, 62, 414, 238);
		scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
		frame.getContentPane().add(scrollPane);
	}
}
